package com.example.taobao;

import androidx.lifecycle.ViewModelProvider;

import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.example.taobao.databinding.MineFragmentBinding;
import com.example.taobao.databinding.XiaoxiFragmentBinding;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class xiaoxiFragment extends Fragment {

    private XiaoxiViewModel mViewModel;
    private XiaoxiFragmentBinding binding;

    public static xiaoxiFragment newInstance() {
        return new xiaoxiFragment();
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {


        View view =inflater.inflate(R.layout.xiaoxi_fragment,null);

        mViewModel =
                new ViewModelProvider(this).get(XiaoxiViewModel.class);

        binding = XiaoxiFragmentBinding.inflate(inflater, container, false);
        View root = binding.getRoot();

        int[] imagebutton = new int[]{R.drawable.userimage,R.drawable.userimage,
                R.drawable.userimage,R.drawable.userimage,R.drawable.userimage,R.drawable.userimage};

        String[] title = new String[]{"theKul","YOUR","liuSan","title","Anew","BeiJin"};




        ListView listView =view.findViewById(R.id.xiaoxilistview);
        List<Map<String,Object>> listitem = new ArrayList<Map<String, Object>>();
        for (int i=0;i<imagebutton.length;i++){
            Map<String,Object> map = new HashMap<String,Object>();
            map.put("image",imagebutton[i]);
            map.put("title",title[i]);
            listitem.add(map);
        }

        SimpleAdapter adapter = new SimpleAdapter(getActivity(),listitem,
                R.layout.item_list, new String[]{"image","title"},new int[]{R.id.userxiaoxiimage,R.id.recytext});

        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent intent;
                switch (i){
                    case 0:
                        intent = new Intent(getActivity(),lineMainActivity2.class);
                        startActivityForResult(intent,4);
                        break;
                    case 1:
                        intent = new Intent(getActivity(),lineMainActivity2.class);
                        startActivityForResult(intent,5);
                        break;
                    case 2:
                        intent = new Intent(getActivity(),lineMainActivity2.class);
                        startActivityForResult(intent,6);
                        break;
                    case 3:
                        intent = new Intent(getActivity(),lineMainActivity2.class);
                        startActivityForResult(intent,7);
                        break;
                    case 4:
                        intent = new Intent(getActivity(),lineMainActivity2.class);
                        startActivityForResult(intent,8);
                        break;
                    default:
                        intent = new Intent(getActivity(),lineMainActivity2.class);
                        startActivityForResult(intent,9);
                        break;
                }
            }
        });
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mViewModel = new ViewModelProvider(this).get(XiaoxiViewModel.class);
        // TODO: Use the ViewModel
    }


}